//
//  TogetherUtils.m
//  Together_iOS
//
//  Created by applex on 14-3-1.
//  Copyright (c) 2014年 QIU Shuang. All rights reserved.
//

#import "TogetherUtils.h"

@implementation TogetherUtils

+ (NSString *)jsonStringFromData:(id)theData {
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:0
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

        return jsonString;
    }else{
        return nil;
    }

}

+ (id)arrayOrNSDictionaryFromJsonString:(NSData *)jsonData{
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
                                                    options:NSJSONReadingAllowFragments
                                                      error:&error];
    
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析错误
        return nil;
    }
    
}


@end
